test: lock in CallToolResult(is_error=True) with non-text content (#348)#2841
Open
cognis-digital wants to merge 1 commit into
Open
Conversation
…delcontextprotocol#348) A FastMCP tool can already report failure while returning rich (non-text) content by returning a CallToolResult with is_error=True directly -- MCPServer passes it through unchanged. This was untested and undocumented, which is what issue modelcontextprotocol#348 reports ("no way to set isError=True for arbitrary tool result content"). Add a regression test proving an image content block plus is_error=True round-trips to the caller over all transports, and a matching requirements manifest entry (source issue:modelcontextprotocol#348). Test-only; no library change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a regression test proving a FastMCP tool can return a
CallToolResultwithis_error=Truecarrying non-text content (an image), and a matching requirements-manifest entry.Why
Issue #348 (good first issue, ready for work) reports that there's "no way to set
isError=Truefor arbitrary tool result content" — e.g. returning an image withisError=True.While looking into it, the capability actually already exists on
main:_handle_call_toolandfunc_metadata.convert_resultpass a tool-returnedCallToolResultthrough unchanged, so a tool can returnCallToolResult(content=[ImageContent(...)], is_error=True)directly. The existing tests only cover this for text content and for the validation/exception paths — the non-text +is_errorcase from #348 wasn't pinned anywhere.This PR locks that behaviour in so it can't silently regress, and documents the pattern in the test docstring. Test-only — no library change.
Verification
tests/interaction/test_coverage.pyrequirements gate passes (new requirement is exercised; test carries a requirement)ruff format --check,ruff check, andpyrightall cleantests/interaction/mcpserver/test_tools.py(42 tests) passesIf maintainers would rather close #348 with a dedicated convenience API instead of documenting the
CallToolResultpassthrough, happy to adjust — this seemed like the lowest-risk way to resolve it.Closes #348.
🤖 Generated with Claude Code